﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CheckList
{
    public partial class ColumnConfigForm : Form{
     //   public delegate void RefreshColumnsDelegate(List<string> col);

     //   public event RefreshColumnsDelegate RefreshColumnEvent = null;

        private static List<string> _checkedColumns = new List<string>();
     //   private List<string> _hideColumns = new List<string>();

        public ColumnConfigForm(List<string> checkedColumns)
        {
            InitializeComponent();
            InitCheckedColumns(checkedColumns);
            ShowCheckedColumns();
        }

        private void ShowCheckedColumns()
        {
            if (_checkedColumns.Contains(lblCheckItem.Text)){
                lblCheckItem.Checked = true;
            }
            if (_checkedColumns.Contains(lblHazard.Text))
            {
                lblHazard.Checked = true;
            }
            if (_checkedColumns.Contains(lblAdviceType.Text))
            {
                lblAdviceType.Checked = true;
            }
            if (_checkedColumns.Contains(lblAdviceNum.Text))
            {
                lblAdviceNum.Checked = true;
            }
            if (_checkedColumns.Contains(lblAdvice.Text))
            {
                lblAdvice.Checked = true;
            }

            if (_checkedColumns.Contains(lblPerson.Text))
            {
                lblPerson.Checked = true;
            }
            if (_checkedColumns.Contains(lblNotes.Text))
            {
                lblNotes.Checked = true;
            }
        }



        private void InitCheckedColumns(List<string> checkedColumns)
        {
            _checkedColumns.Clear();
            foreach (string s in checkedColumns){
                _checkedColumns.Add(s);
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {   
            _checkedColumns.Clear();
            foreach (Control ctr in this.Controls){
                if (ctr is CheckBox && ((CheckBox)ctr).Checked)
                { 
                        _checkedColumns.Add(ctr.Text);
                }
            }
//            OnColumnsCHanged();
            Program.Workspace.HideColumns(_checkedColumns);
            this.Close();
        }

       
    }
}
